package com.peng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.peng.pojo.Student;
import com.peng.pojo.Teacher;
import com.peng.service.TeacherService;
import com.peng.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.List;

@RestController
@RequestMapping("/sms/teacherController")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public Result getTeachers(
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize,
            String name,
            String clazzName
    ){
        IPage<Teacher> iPage=teacherService.getTeachers(pageNo,pageSize,name,clazzName);
        return Result.ok(iPage);
    }

    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(@RequestBody Teacher teacher){
        teacherService.saveOrUpdate(teacher);
        return Result.ok();
    }

    @DeleteMapping("/deleteTeacher")
    public Result delStudentById(@RequestBody List<Integer> list){
        for (Integer integer : list) {
            Teacher byId = teacherService.getById(integer);
            String portraitPath = byId.getPortraitPath();
            String path ="F:/学习笔记/myproject/zhxy_db/src/main/resources/public/";
            String str=path+portraitPath;
            new File(str).delete();
        }
        teacherService.removeByIds(list);
        return Result.ok();
    }
}
